<!-- 编辑批次Modal -->
<div class="modal fade" id="edit-custom-contact" tabindex="-1">
    <div class="modal-dialog">
        <form id="edit_contact_form" name="edit_contact_form" method="post" action="/custom/index/saveContact">
            <input type="hidden" name="custom_id" value="{$custom.id}"/>
            <input type="hidden" name="id" value=""/>
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h4 class="modal-title" id="batch-title">编辑联系信息</h4>
                </div>
                <div class="modal-body">
                    <div class="form-group">
                        <label>姓名<span class="text-important">*</span></label>
                        <input name="name" class="form-control" type="text" value="">
                    </div>
                    <div class="form-group">
                        <label>职位</label>
                        <input name="job" class="form-control" type="text" value="">
                    </div>
                    <div class="form-group">
                        <label>手机</label>
                        <input id="phone" name="phone" class="form-control" type="text" value="">
                    </div>
                    <div class="form-group">
                        <label>固话</label>
                        <input id="tel" name="tel" class="form-control" type="text" value="">
                    </div>
                    <!--<div class="form-group">-->
                    <!--<label>类型</label>-->
                    <!--<input name="type_name" class="form-control" type="text" value="">-->
                    <!--</div>-->
                    <div class="form-group">
                        <label>来源</label>
                        <input name="source" class="form-control" type="text" value="">
                    </div>
                    <div class="form-group">
                        <label>备注</label>
                        <textarea name="remark" class="form-control" type="text"></textarea>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="submit" class="btn btn-primary">保存</button>
                </div>
            </div>
        </form>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function () {
        $('[data-toggle="modal"][data-target="#edit-custom-contact"]').click(function () {
            reset_edit_contact_form();
            var $this = $(this);
            var node = $this.parent().parent();
            edit_edit_contact_form(node);
        });

        $('#edit_contact_form').validate({
            submitHandler: function () {
                $.post($("#edit_contact_form").attr("action"), $("#edit_contact_form").serialize(), function (data) {
                    if (data === "0") {
                        alertify.alert("保存成功!", function () {
                            $('#edit_contact_form').modal('hide');
                            location.reload();
                        });
                    } else {
                        alertify.alert(data);
                    }
                }).error(function (msg, url, line) {
                    alert(msg.responseText);
                });
            },
            ignore: "",
            rules: {
                name: {
                    required: true
                },
                job: {
                    required: true
                },
                phone: {
                    isPhone: true
                },
                tel: {
                    atLeastOne: ['#phone', '#tel']
                }
            },
            messages: {
                name: {
                    required: "请填写名称"
                },
                job: {
                    required: "请填写职位"
                },
                phone: {
                    isPhone: "请填写正确的手机号"
                },
                tel: {
                    atLeastOne: "手机和固话请至少填写一项"
                }
            }
        });

    });

    function reset_edit_contact_form() {
        $('#edit_contact_form input[name="id"]').val('');
        $('#edit_contact_form input[name="name"]').val('');
        $('#edit_contact_form input[name="phone"]').val('');
        $('#edit_contact_form input[name="tel"]').val('');
        $('#edit_contact_form input[name="job"]').val('');
        $('#edit_contact_form input[name="type_name"]').val('');

        $('#edit_contact_form input[name="source"]').val('');
        $('#edit_contact_form textarea[name="remark"]').val('');
    }

    function edit_edit_contact_form(node) {
        $('#edit_contact_form input[name="id"]').val(node.data('valueid'));
        $('#edit_contact_form input[name="name"]').val(node.data('name'));
        $('#edit_contact_form input[name="phone"]').val(node.data('phone'));
        $('#edit_contact_form input[name="tel"]').val(node.data('tel'));
        $('#edit_contact_form input[name="job"]').val(node.data('job'));
        $('#edit_contact_form input[name="type_name"]').val(node.data('type_name'));

        $('#edit_contact_form input[name="source"]').val(node.data('source'));
        $('#edit_contact_form textarea[name="remark"]').val(node.data('remark'));
    }

</script>